package com.example.sunny.view.weather

import android.os.Bundle
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RadioGroup
import androidx.fragment.app.Fragment
import com.example.sunny.R
import com.example.sunny.utils.StringUtils.showToast
import com.google.android.material.appbar.MaterialToolbar
import kotlinx.android.synthetic.main.settings_fragment.*

class SettingsFragment:Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.settings_fragment,container,false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        val toolbar = view.findViewById<MaterialToolbar>(R.id.settingsToolbar)
        toolbar.setNavigationOnClickListener {
        }


        val activity = activity as WeatherActivity
        if (activity.viewModel.isCentigrade.value != false){
            radio_1.isChecked = true
        }else{
            radio_2.isChecked = true
        }
        val radioGroup = view.findViewById<RadioGroup>(R.id.radioGroup)
        radioGroup.setOnCheckedChangeListener { group, checkedId ->
            when(checkedId){
                R.id.radio_1 -> {
                    activity.viewModel.isCentigrade.value = true
                    radio_1.isChecked = true
                }
                R.id.radio_2 -> {
                    activity.viewModel.isCentigrade.value = false
                    radio_2.isChecked = true
                }
            }
        }
    }
}